package net.jueb.majong.voice.util;

import java.io.File;
import java.util.HashSet;
import java.util.Properties;
import java.util.Set;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import net.jueb.util4j.common.game.env.Environment;

public class Config {
	
	private static Logger log=LoggerFactory.getLogger(Config.class);
	public static final Environment env=Environment.getInstance();
	public static final Set<String> ACCESS_ORIGIN_LIST=new HashSet<String>();//跨域主机白名单
	
	public static boolean VOICE_CLEAN=true;//音频清理
	public static int VOICE_KEEP_TIME_MINUTES=30;//文件保留时间(分)
	public static String VOICE_DIR;//语音存放目录
	public static String VOICE_FORMAT_DIR;//语音转码存放目录
	
	public static int MP3_BitRate;
	public static int MP3_SamplingRate;
	public static int MP3_Channels;
	public static int MP3_Volume;
	
	static{
		load();
	}
	
	/**
	 * 加载配置文件
	 */
	public static void load()
	{
		Properties pp = new Properties();
		try {
			pp.load(Config.class.getClassLoader().getResourceAsStream("conf/config.properties"));
			//跨域允许列表
			String[] ORIGIN_ACCESS_LIST_=pp.getProperty("ACCESS_ORIGIN_LIST","").split(",");
			for(String web:ORIGIN_ACCESS_LIST_)
			{
				ACCESS_ORIGIN_LIST.add(web);
			}
			VOICE_CLEAN=Boolean.parseBoolean(pp.getProperty("VOICE_CLEAN","true"));
			VOICE_KEEP_TIME_MINUTES=Integer.parseInt(pp.getProperty("VOICE_KEEP_TIME_MINUTES","30"));
			MP3_BitRate=Integer.parseInt(pp.getProperty("MP3_BitRate","128000"));
			MP3_SamplingRate=Integer.parseInt(pp.getProperty("MP3_SamplingRate","44100"));
			MP3_Channels=Integer.parseInt(pp.getProperty("MP3_Channels","2"));
			MP3_Volume=Integer.parseInt(pp.getProperty("MP3_Volume","100"));
			VOICE_DIR=pp.getProperty("VOICE_DIR");
			VOICE_FORMAT_DIR=pp.getProperty("VOICE_FORMAT_DIR");
			new File(VOICE_DIR). mkdirs();
			new File(VOICE_FORMAT_DIR). mkdirs();
		} catch (Exception e) {
			log.error(e.getMessage(),e);
		}
	}
}
